#include "netchatroom.h"

void NetChatRoom::join(NetChatterPtr a_chatter)
{
    m_chatters.insert(a_chatter);

    for(const NetChatMsg &l_msg:recent_msgs_) {
        a_chatter->deliver(l_msg);
    }
}

void NetChatRoom::leave(NetChatterPtr a_chatter)
{
    m_chatters.erase(a_chatter);
}

void NetChatRoom::deliver(const NetChatMsg &a_msg)
{
    recent_msgs_.push_back(a_msg);
    while (recent_msgs_.size() > max_recent_msgs) {
        recent_msgs_.pop_front();
    }

    for(NetChatterPtr l_chatter:m_chatters) {
        l_chatter->deliver(a_msg);
    }
}
